﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Air_condition.DO;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Air_condition.DO
{
    [Serializable]
    class Roof : Construction
    {
        // Instance  vars  for roof and iheritance from construction
        private double dbabsorptionCoefficient;
        private double dbthermalRadiation;
        private double dbscoreEffect;
        private double dbscoreEffectOfRoofColor;
        private string ssurface;
        private string stypeMaterial;
        private double dblength;

        public double dbLength
        {
            get { return dblength; }
            set { dblength = value; }
        }
        private double dbwidth;

        public double dbWidth
        {
            get { return dbwidth; }
            set { dbwidth = value; }
        }

        //  set/get Absorption Coefficient
        public double AbsorptionCoefficient
        {
            get { return dbabsorptionCoefficient; }
            set { dbabsorptionCoefficient = value; }
        }

        //  set/get Therma lRadiation
        public double ThermalRadiation
        {
            get { return dbthermalRadiation; }
            set { dbthermalRadiation = value; }
        }

        //  set/get Score Effect
        public double ScoreEffect
        {
            get { return dbscoreEffect; }
            set { dbscoreEffect = value; }
        }

        //  set/get Score Effect Of Roof Color
        public double ScoreEffectOfRoofColor
        {
            get { return dbscoreEffectOfRoofColor; }
            set { dbscoreEffectOfRoofColor = value; }
        }

        //  set/get Type Material
        public string TypeMaterial
        {
            get { return stypeMaterial; }
            set { stypeMaterial = value; }
        }

        private int isurface;

        public int Surface
        {
            get { return isurface; }
            set { isurface = value; }
        }

        private int icolor;

        public int Icolor
        {
            get { return icolor; }
            set { icolor = value; }
        }
        public override void CalculateTemperatureDiff(double dbinsideRoomTemp, double dboutsideRoomTemp)
        {
            double dbr = dbthermalRadiation / 0.88;
            double dbtn = dboutsideRoomTemp + ((dbabsorptionCoefficient * dbr) / 20);
            dbtemperatureDiff = dbtn - dbinsideRoomTemp;
        }

        //  Nhiệt bức xạ truyền qua mái Q12
        public override double CalculateConstructionHeatTransfer(double dboutsideTemperature, double dbInsideTemperature)
        {
            //  Loại mái user sẽ chọn từ library
            CalculateTemperatureDiff(dbInsideTemperature, dboutsideTemperature);
            //  Nếu là mái sẫm 
            if (icolor == 0)
                dbscoreEffectOfRoofColor = 1;

            else
            {
                //  Nếu là mái sáng
                if (icolor == 1)
                {
                    dbscoreEffectOfRoofColor = 0.87;
                }
                else
                {
                    //  Nếu là mái màu trung bình
                    if (icolor == 2)
                    {
                        dbscoreEffectOfRoofColor = 0.87;
                    }
                }
            }

            return dbarea * dbheatTransferCoefficient * dbtemperatureDiff * dbscoreEffectOfRoofColor;
            //  dbare, dboutDoorTemperature, dbinsideTemperature lấy số liệu từ user nhập
            //  dbabsorptionCoefficient, dbthermalRadiation, dbheatTransferCoefficient,dbscoreEffectOfRoofColor lấy số liệu từ library
        }

        public object Clone()
        {
            object clone;
            try
            {
                using (MemoryStream stream = new MemoryStream())
                {

                    BinaryFormatter formatter = new BinaryFormatter();

                    // Serialize this object

                    formatter.Serialize(stream, this);

                    stream.Position = 0;

                    // Deserialize to another object

                    clone = formatter.Deserialize(stream);

                }
                return clone;
            }
            catch (Exception e)
            {
                return e;
            }

        }

    }
}
